package com.example.park_management.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.park_management.domain.Assets;
import com.example.park_management.service.AssetsService;
import com.example.park_management.mapper.AssetsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author xiaoming
* @description 针对表【assets(资产)】的数据库操作Service实现
* @createDate 2024-05-28 17:04:33
*/
@Service
public class AssetsServiceImpl extends ServiceImpl<AssetsMapper, Assets>
    implements AssetsService{

    @Autowired
    private AssetsMapper assetsMapper;

    @Override
    public List<Assets> getOwnerList(Integer roomId) {
        QueryWrapper<Assets> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("room_id", roomId);

        return assetsMapper.selectList(queryWrapper);
    }
    // 假设这个方法用来检查给定的roomId和ownerId是否已存在关联
    public boolean isAssetAssociatedWithRoom(Integer roomId, Integer ownerId) {
        QueryWrapper<Assets> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("room_id", roomId).eq("owner_id", ownerId);
        return baseMapper.exists(queryWrapper);
    }
    public void removeAllAssociationsByRoomId(Integer roomId) {
        QueryWrapper<Assets> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("room_id", roomId);
        baseMapper.delete(queryWrapper);
    }
}




